"""
Copyright 2009, Thomas Dejanovic.

This is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of
the License, or (at your option) any later version.

This software is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this software; if not, write to the Free
Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA, or see the FSF site: http://www.fsf.org.

This is a very simple sanity test for the Digilent S3 board.
"""

xml_s3board = """
    <Struct name="'s3board'">
        <target> 'small apb slave' </target>
        <hatch_leaf> False </hatch_leaf>
        <Register name="'button'">
            <comment> 'This is the bank of 4 buttons on the bottom left edge of the board.' </comment>
            <bit_width> 4 </bit_width>
            <default> 0 </default>
            <sw> 'r' </sw>
            <hatch_leaf> True </hatch_leaf>
            <external> True </external>
        </Register>
    </Struct>
    """

xml_led = """
    <Register name="'led'">
        <comment> 'This is the bank of 8 LEDs on the bottom left corner of the board.' </comment>
    </Register>
    """

s3board = Struct(name='this gets replaced', xml=xml_s3board)    # Set the 'xml' property to use XML.

# This register is now defined from one level above in xml_s3board, so it is 
# NOT needed in python.
#hatchBlock.Register('button', bit_width=4, sw='r', external=True,
#    comment="""This is the bank of 4 buttons on the bottom left edge of the board.""")

# This is NOT defined in the XML, so it IS needed in python.
s3board.Register('switch', bit_width=8, sw='r', external=True,
    comment="""This is the bank of 8 switches on the bottom right edge of the board.""")

# This register has some properties defined in xml_led, and some in python. The 
# final design should have all properties from both formats.
# Please note that for any node DECLARED in BOTH the XML and the python, the 
# final design gets two copies with the same name, and the property checker 
# should complain when hatching the design.  In other words, if the contents of
# xml_led were instead in xml_s3board (and the node below did NOT have an 'xml'
# property) two copies would be created.
s3board.Register('led', bit_width=8, sw='rw', hw='r', xml=xml_led)

cPack = s3board.Pack('cPack',
    comment="""This is the 4x7 segment display on the bottom right corner of the board. Values are desplayed in hex.""")
cPack.Register('c3', bit_width=4,  sw='rw', hw='ir')
cPack.Register('c2', bit_width=4,  sw='rw', hw='ir')
cPack.Register('c1', bit_width=4,  sw='rw', hw='ir')
cPack.Register('c0', bit_width=4,  sw='rw', hw='ir')

hatchBlock = s3board    # Set s3board to hatch's default top node identifier.


